package com.um.jdy.mp.platform.manager;

import com.um.jdy.common.platform.entity.po.App;
import com.um.jdy.common.platform.entity.po.Company;
import com.um.jdy.common.platform.service.AppService;
import com.um.jdy.common.platform.service.CompanyService;
import com.um.jdy.common.platform.service.CompanyUserService;
import com.um.jdy.mp.platform.entity.vo.MpAppVO;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import com.um.springboot.starter.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppManager extends BaseManager<AppService> {

    @Autowired
    CompanyUserService companyUserService;

    @Autowired
    CompanyService companyService;

    /**
     * 详情
     *
     * @return
     */
    public Response<MpAppVO> getMpAppVO() {

        MpAppVO appVO = new MpAppVO();

        App app = service.getEntity("com_id", getComId());
        if(app != null){
           appVO.setAppId(app.getMpAppId());
        }

        Company company = companyService.getEntity("platform_id",getComId());
        if(company != null){
            if(!StringUtil.isEmpty(company.getUserDomain()))
                appVO.setDomain(company.getUserDomain());
            else
                appVO.setDomain(company.getDomain());
        }

        return Response.success(appVO);
    }
}
